package ArrayDemo2;

/**
 * Created by sunwei on 2017/10/12
 * Time:20:15
 */
public class LowArrayApp {
    public static void main(String[] args) {
        int size=100;
        LowerArray arr = new LowerArray(size);
        int nElems = 0;
        int j;

        arr.setElem(0,77);
        arr.setElem(1,88);
        arr.setElem(2,44);
        arr.setElem(3,11);
        arr.setElem(4,33);
        arr.setElem(5,99);
        arr.setElem(6,00);
        arr.setElem(7,22);
        arr.setElem(8,55);
        arr.setElem(9,66);
        nElems = 10;
        /*
        遍历显示数组
         */
        for(j = 0;j<nElems ; j++) {
            System.out.print(arr.getElem(j)+ " ");
            System.out.println(" ");
        }
        System.out.println("寻找值为26的元素");
        int searchKey = 26;
        for(j = 0; j<nElems ; j++) {
            if (arr.getElem(j)==searchKey) {
                  break;
            }
        }
        if (j==nElems) {
              System.out.println("Can't find !!!");
        }else {
            System.out.println("Found" + searchKey);
        }
        /*
        删除value=55的元素，先找值为55的元素的下标
         */
        for(j = 0;j<nElems ;j++) {
            if (arr.getElem(j)==55) {
                  break;
            }
        }
        /*
        具体删除的做法是：将j下标后面的元素往前移动
         */
        for(int k = j;k<nElems ;k++) {
            arr.setElem(k,arr.getElem(k+1));
        }
        nElems --;

        /*
        删除后遍历显示数组
         */
        for(int i = 0;i<nElems ;i++) {
            System.out.print(arr.getElem(i)+" ");
        }

    }
}
